<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <script type="text/javascript">
        function check_input(form)
	{
            if((form.username.value=="")&&(form.orders_id.value=="")) {
		alert("请输入下订单人或订单号");
		form.username.select();
		return(false);
            }
           
	   return(true);
	}
        </script>
    </head>
    <body>
        <?php
        // put your code here
        include ("../conn/conn.php");
        $conn = prepare();
        ?>
        <table width="550" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
          <td height="20" bgcolor="#B0E0E6"><div align="center">订单查询</div></td>
        </tr>
        <tr>
          <td height="50" bgcolor="#555555"><table width="550" height="50" border="0" align="center" cellpadding="0" cellspacing="1">
            <tr>
              <td bgcolor="#FFFFFF">
			  <table width="550" height="50" border="0" align="center" cellpadding="0" cellspacing="0">
                <form name="form3" method="post" action="searchorder.php" onSubmit="return check_input( this)">
				<tr>
                                    <td height="25"><div align="center">下订单人姓名:<input type="text" name="username" size="20" maxlength="20">
                                            订单号:<input type="number" name="orders_id" size="5" maxlength="5" max="99999" min="1"></div></td>
                </tr>
                <tr>
                  <td height="25">
                    <div align="center">
					    <input type="hidden" value="show_find" name="show_find">
                        <input name="button" type="submit" value="查 找">
                    </div></td>
                </tr>
			    </form>
              </table></td>
            </tr>
          </table></td>
        </tr>
</table>
      <table width="550" height="20" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
          <td>&nbsp;</td>
        </tr>
      </table>
	  <?php
	    if(@$_POST['show_find']!=""){
	      $username=trim($_POST['username']);
		  $orders_id=trim($_POST['orders_id']);
		  if($username==""){
		       $sql= exectue_sql_statement($conn, "select * from Book, Members, Orders where orders_id=$orders_id and Book.book_id=Orders.book_id and Members.members_id=Orders.orders_id");
		   }
		  elseif($orders_id==""){
		      $sql=exectue_sql_statement($conn, "select * from Book, Members, Orders where members_name='$username' and Book.book_id=Orders.book_id and Members.members_id=Orders.orders_id");
		   }
		  else{
		      $sql=exectue_sql_statement($conn, "select * from Book, Members, Orders where members_name='$username' and orders_id=$orders_id and Book.book_id=Orders.book_id and Members.members_id=Orders.orders_id");
		  }
		  $info=sqlsrv_fetch_array($sql);
		  if($info==false){
		      echo "<div algin='center'>对不起,没有查找到该订单!</div>";    
		   }
		   else{
	  ?>
	  <table width="550" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
          <td height="20" bgcolor="#B0E0E6"><div align="center" style="color: #FFFFFF">查询结果</div></td>
        </tr>
        <tr>
          <td height="50" bgcolor="#555555"><table width="550" height="50" border="0" align="center" cellpadding="0" cellspacing="1">
            <tr>
              <td width="77" bgcolor="#FFFFFF"><div align="center">订单号</div></td>
              <td width="77" bgcolor="#FFFFFF"><div align="center">图书名称</div></td>
              <td width="77" bgcolor="#FFFFFF"><div align="center">单价</div></td>
              <td width="77" bgcolor="#FFFFFF"><div align="center">数量</div></td>
              <td width="77" bgcolor="#FFFFFF"><div align="center">用户名</div></td>
              <td width="77" bgcolor="#FFFFFF"><div align="center">订单日期</div></td>
            </tr>
			<?php
			  do{
			?>
            <tr>
              <td height="25" bgcolor="#FFFFFF"><div align="center"><?php echo $info['orders_id'];?></div></td>
              <td height="25" bgcolor="#FFFFFF"><div align="center"><?php echo $info['book_name'];?></div></td>
              <td height="25" bgcolor="#FFFFFF"><div align="center"><?php echo $info['unit_price'];?></div></td>
              <td height="25" bgcolor="#FFFFFF"><div align="center"><?php echo $info['orders_amount'];?></div></td>
              <td height="25" bgcolor="#FFFFFF"><div align="center"><?php echo $info['members_name'];?></div></td>
              <td height="25" bgcolor="#FFFFFF"><div align="center"><?php echo $info['orders_date'];?></div></td>
            </tr>
			<?php
			   }while($info=sqlsrv_fetch_array($sql));
			?>
          </table></td>
        </tr>
      </table>
	    <?php
		   }
		  }
		?>
    </body>
</html>
